package org.forum.controller;

import java.util.Iterator;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.forum.domain.Forum;
import org.forum.domain.MainTopic;
import org.forum.domain.User;
import org.forum.service.PersonalHomepageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PersonalHomepageController {
	
	Logger logger = LoggerFactory.getLogger(PersonalHomepageController.class);
	
	private PersonalHomepageService personalHomepageService;
	
	private List<Forum> forums;
	
	private List<MainTopic> correspondingMainTopics = null;
	
	private int pageN_personalHomepage;
	
	private int pageSize=3;
	
	String sortBy="addTime";
	
	/**
	 * @pass_Test
	 * 得到用户关注的论坛
	 */
	public String userFollowedForums(){
		forums = personalHomepageService.getUserFollowedForums();
		return "userFollowedForum";
	}

	/**
	 * @pass_Test
	 * 得到个人首页中的动态
	 * @return
	 */
	public String correspondingMainTopics(){
		Object o = ServletActionContext.getRequest().getSession().getAttribute("pageN_personalHomepage");
		if(o!=null){
			//pageN_personalHomepage = (int)o;
			//临时替换
			pageN_personalHomepage = 0;
		}
		List<Forum> forums = personalHomepageService.getUserFollowedForums();
		correspondingMainTopics = personalHomepageService.getMainTopicsByFourms(forums, pageN_personalHomepage, pageSize, sortBy);
		if(logger.isDebugEnabled()){
			logger.debug("correspondingMainTopics.size:" + correspondingMainTopics.size());
		}
		return "correspondingMainTopics";
	}
	
	public List<Forum> getForums() {
		return forums;
	}

	public void setPersonalHomepageService(PersonalHomepageService personalHomepageService) {
		this.personalHomepageService = personalHomepageService;
	}

	public List<MainTopic> getCorrespondingMainTopics() {
		return correspondingMainTopics;
	}
}
